package com.dreamsail.core.model.system;

import lombok.Data;

import java.util.List;

@Data
public class PageInfo<T> {

    /**
     * 一页大小
     */
    private int pageSize;

    /**
     * 页码（从1开始，如果是0，则设置为1）
     */
    private int pageNo;

    /**
     * 数据列表
     */
    private List<T> dataList;

    /**
     * 总数
     */
    private long total;

    /**
     * 总页数
     */
    private int pageCount;

    public PageInfo(List<T> resultContent, long num, PageReq<T> pageReq) {
        this.dataList = resultContent;
        this.total = num;
        if(pageReq != null){
            this.pageSize = pageReq.getPageSize();
            this.pageNo = pageReq.getPageNo();
            this.pageCount = (int) (this.total / this.pageSize);
            if(this.total % this.pageSize != 0 ){
                this.pageCount ++;
            }
        }
    }
}
